#!/bin/bash

# 这个脚本用于生成macOS应用程序图标(.icns)文件
# 使用sips（macOS自带）处理图像

# 创建临时图标目录
mkdir -p build/icon.iconset

# 源图像文件
SOURCE_IMAGE="build/logo.png"

# 获取源图像尺寸
width=$(sips -g pixelWidth "$SOURCE_IMAGE" | grep pixelWidth | awk '{print $2}')
height=$(sips -g pixelHeight "$SOURCE_IMAGE" | grep pixelHeight | awk '{print $2}')

echo "处理图像: $SOURCE_IMAGE ($width x $height)"

# 处理不同尺寸
sips -z 16 16 "$SOURCE_IMAGE" --out build/icon.iconset/icon_16x16.png
sips -z 32 32 "$SOURCE_IMAGE" --out build/icon.iconset/icon_16x16@2x.png
sips -z 32 32 "$SOURCE_IMAGE" --out build/icon.iconset/icon_32x32.png
sips -z 64 64 "$SOURCE_IMAGE" --out build/icon.iconset/icon_32x32@2x.png
sips -z 128 128 "$SOURCE_IMAGE" --out build/icon.iconset/icon_128x128.png
sips -z 256 256 "$SOURCE_IMAGE" --out build/icon.iconset/icon_128x128@2x.png
sips -z 256 256 "$SOURCE_IMAGE" --out build/icon.iconset/icon_256x256.png
sips -z 512 512 "$SOURCE_IMAGE" --out build/icon.iconset/icon_256x256@2x.png
sips -z 512 512 "$SOURCE_IMAGE" --out build/icon.iconset/icon_512x512.png
sips -z 1024 1024 "$SOURCE_IMAGE" --out build/icon.iconset/icon_512x512@2x.png

echo "所有尺寸已处理完成，正在创建.icns文件..."

# 使用iconutil将图标集转换为.icns文件
iconutil -c icns build/icon.iconset

# 清理临时目录
rm -rf build/icon.iconset

echo "ICNS图标文件已创建: build/icon.icns" 